//
// Created by win10 on 2024/12/30.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_STUDENTS 20
#define MAX_NAME_LENGTH 20

// 结构体定义，用于存储学生信息（姓名和成绩）
typedef struct {
    char name[MAX_NAME_LENGTH];
    int score;
} Student;

// 交换两个学生结构体的函数
void swap(Student *a, Student *b) {
    Student temp = *a;
    *a = *b;
    *b = temp;
}

// 比较函数，用于qsort，按照成绩降序，成绩相同按名字字典序升序
int compare(const void *a, const void *b) {
    Student *s1 = (Student *)a;
    Student *s2 = (Student *)b;
    if (s1->score!= s2->score) {
        return s2->score - s1->score;
    }
    return strcmp(s1->name, s2->name);
}

int main() {
    int n;
    scanf("%d", &n);
    Student students[MAX_STUDENTS];
    for (int i = 0; i < n; i++) {
        scanf("%s %d", students[i].name, &students[i].score);
    }

    qsort(students, n, sizeof(Student), compare);

    for (int i = 0; i < n; i++) {
        printf("%s %d\n", students[i].name, students[i].score);
    }

    return 0;
}